from sqlalchemy import create_engine, text


def conn_db1():
    #数据库的对象
    HOST = '127.0.0.1'
    PORT = 3306
    DATABASE = 'itbz'
    USER = 'root'
    PWD = 'root'

    DB_URL = f'mysql+pymysql://{USER}:{PWD}@{HOST}:{PORT}/{DATABASE}'

    engine = create_engine(DB_URL)

    #执行一个sql
    sql = 'select 1'
    conn = engine.connect()
    rs= conn.execute(text(sql))
    print(rs.fetchone())

def conn_db2():
    # 数据库的对象
    HOST = '127.0.0.1'
    PORT = 3306
    DATABASE = 'itbz'
    USER = 'root'
    PWD = 'root'

    DB_URL = f'mysql+pymysql://{USER}:{PWD}@{HOST}:{PORT}/{DATABASE}'

    engine = create_engine(DB_URL)

    # 执行一个sql
    sql = 'create table t_user(id int primary key auto_increment , name varchar(32))'
    with engine.connect() as conn:
        conn.execute(text(sql))

if __name__ == '__main__':
    conn_db2()